package org.wak.gui.scumm
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	import flash.ui.Mouse;
	
	import org.wak.action.actions.AdventureActions;
	import org.wak.character.display.AbstractCharacterDisplay;
	import org.wak.gui.IAdventureGui;
	import org.wak.gui.events.GuiEvent;
	import org.wak.inventory.Inventory;
	import org.wak.main.AdventureMaster;
	import org.wak.main.text.IStringSet;
	import org.wak.utils.WakSimpleButton;

	/**
	 * Manages the scumm user interface 
	 * 
	 */	
	public class ScummGui extends Sprite implements IAdventureGui
	{
		private var mMouseCursor:ScummCursor = null ;
		
		private var mBackPanel:Shape = new Shape() ;
		
		private var mGuiSettings:XML = null ;
		
		protected const kPanelHPercent:Number = 27.5 ;
		
		// color of the panel
		private var mPanelColor:uint = 0x000000;
		// background display object of the buttons panel
		private var mPanelBg:DisplayObject = null;
		
		private var mResourceManager:Class = null ;
		private var mTextManager:IStringSet = null ;
		
		private var stageHeight:Number;
		
		// Non Asoc array of buttons.
		private var mButtonsArray:Array = null ;
		// Asoc array of buttons
		private var mButtonsByNameArray:Array = null ;
		private var mButtonHolder:MovieClip = new MovieClip();
		
		private var mButtonStyle:TextFormat = null ;
		private var mFeedbackStyle:TextFormat = null ;
		private var mFeedbackHighlightStyle:TextFormat = null ;
		private var mButtonOverStyle:TextFormat = null ;
		
		private var mFeedbackFont:String = "Alte" ;
		private var mFeedbackFontColor:uint = 0xd850d8 ;
		private var mFeedbackFontHLColor:uint = 0xFFFFFF ;
		private var mFeedbackSize:int = 16 ;
		
		// position on the screen of the InventoryDisplay.
		private var mInventoryPosition:Point = null ;
		
		// rows of items in the inventory
		private var mInventoryRows:int = 2 ;
		
		// cols of items in the inventory.
		private var mInventoryCols:int = 2 ;
		
		// inventory item width
		private var mInventoryItemWidth:int = 40 ;
		
		// inventory item height
		private var mInventoryItemHeight:int = 40 ;
		
		// inventory buttons.
		private var mInvScrollBtnUp:WakSimpleButton = null ;
		private var mInvScrollBtnDown:WakSimpleButton = null ;
		
		private var mFeedbackText:TextField = null ;
		
		private var mScummInventory:ScummInventoryDisplay = null ;
		
		private var mEnabled:Boolean = true ;
		
		/**
		 * Constructor 
		 * @param pGuiSettings an XML with the scumm gui config.
		 * 
		 */		
		public function ScummGui(pGuiSettings:XML = null)
		{
			super();
			
			mButtonsArray = new Array();
			mButtonsByNameArray = new Array();
			
			mButtonStyle = new TextFormat();
			mButtonStyle.font = "Alte" ;
			mButtonStyle.align = TextFormatAlign.CENTER ;
			mButtonStyle.color = 0x782c78 ;
			mButtonStyle.size = 18 ;
			
			mButtonOverStyle = new TextFormat();
			mButtonOverStyle.font = "Alte" ;
			mButtonOverStyle.align = TextFormatAlign.CENTER ;
			mButtonOverStyle.color = 0xd850d8 ;
			mButtonOverStyle.size = 18 ;
			
			
			
			mResourceManager = AdventureMaster.Resources ;
			mTextManager = AdventureMaster.Texts ;
			mGuiSettings = pGuiSettings ;
			mMouseCursor = new ScummCursor();
			
			mFeedbackText = new TextField();
			
			if( mGuiSettings != null)
				LoadSettings(mGuiSettings);
			
			mFeedbackStyle = new TextFormat();
			mFeedbackStyle.font = mFeedbackFont ;
			mFeedbackStyle.align = TextFormatAlign.CENTER ;
			mFeedbackStyle.color = mFeedbackFontColor ;
			mFeedbackStyle.size = mFeedbackSize ;
			
			mFeedbackHighlightStyle = new TextFormat();
			mFeedbackHighlightStyle.font = mFeedbackFont ;
			mFeedbackHighlightStyle.align = TextFormatAlign.CENTER ;
			mFeedbackHighlightStyle.color = mFeedbackFontHLColor ;
			mFeedbackHighlightStyle.size = mFeedbackSize ;
			
			addEventListener(Event.ADDED_TO_STAGE, OnAddedToStage );
			
			var fPlayerInventory:Inventory = AdventureMaster.CharactersMngr.GetCharacter( AdventureMaster.defaultPlayerCharacterId ).inventory ;
			mScummInventory = new ScummInventoryDisplay(fPlayerInventory,mInventoryRows,mInventoryCols, mInventoryItemWidth, mInventoryItemHeight) ;
			mScummInventory.arrowUp = mInvScrollBtnUp ;
			mScummInventory.arrowDown = mInvScrollBtnDown ;
			 
		}
		
		/**
		 * Set the feedback text of the interface with the content of pText 
		 * @param pText feedback text
		 * 
		 */		
		public function SetFeedbackText(pText:String):void
		{
			mFeedbackText.text = pText ;
			mFeedbackText.setTextFormat( mFeedbackStyle );
		}
		
		/**
		 * change the color of the feedback text if value is true. 
		 * @param value 
		 * 
		 */		
		public function set enableHighlight(value:Boolean):void
		{
			if( value == true)
			{
				mFeedbackText.setTextFormat( mFeedbackHighlightStyle );
			}
			else
			{
				mFeedbackText.setTextFormat( mFeedbackStyle );
			}
		}
		
		/**
		 * Toggles selected a given button. 
		 * @param pButtonId button id
		 * 
		 */		
		public function ToggleSelectedButton( pButtonId:String, pState:Boolean ):void
		{
			var fButton:WakSimpleButton = mButtonsByNameArray[pButtonId] as WakSimpleButton;
			if(fButton == null)
				return ;
			fButton.selected = pState ;
		}
		
		public function SetMouseCursor(pCursorLayer:Sprite):void
		{
			Mouse.hide() ;
			pCursorLayer.addChild(mMouseCursor);
		}
		
		public function RemoveMouseCursor(pCursorLayer:Sprite):void
		{
			Mouse.show() ;
			if( pCursorLayer.contains(mMouseCursor) )
				pCursorLayer.removeChild(mMouseCursor);
		}
		
		public function get mouseCursor():DisplayObject 
		{
			return mMouseCursor ;
		}
		
		protected function OnAddedToStage(event:Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, OnAddedToStage );
			
			var fStageH:Number = stage.stageHeight ;
			var fStageW:Number = stage.stageWidth ;
			stageHeight = stage.stageHeight;
			trace("height",stageHeight);
			
			// the gui panel usually is the 27.5 % of the screen height.
			var fPanelH:Number = kPanelHPercent * fStageH / 100 ;
			
			mBackPanel = new Shape();
			mBackPanel.graphics.beginFill(mPanelColor,1);
			mBackPanel.graphics.drawRect(0,0,fStageW,fPanelH);
			mBackPanel.graphics.endFill();
			
			mBackPanel.y = fStageH - fPanelH ;
			
			// add the back panel
			this.addChild( mBackPanel );
			
			// if there is a bavkground add it
			if(mPanelBg != null)
			{
				mPanelBg.y = mBackPanel.y ;
				this.addChild(mPanelBg);
			}
			
			mFeedbackText.embedFonts = true ;
			mFeedbackText.width = mBackPanel.width ;
			mFeedbackText.height = 24 ;
			//mFeedbackText.text = "Hola" ;
			mFeedbackText.selectable = false ;
			mFeedbackText.x = stage.stageWidth/2 - mBackPanel.width/2 ;
			mFeedbackText.y = mBackPanel.y ;
			mFeedbackText.setTextFormat(mFeedbackStyle);
			//mFeedbackText.borderColor = 0xFFFFFF ;
			//mFeedbackText.border = true ;
			
			this.addChild(mFeedbackText);
			
			// add buttons.
			for each( var button:WakSimpleButton in mButtonsArray)
			{
				mButtonHolder.addChild( button );
				button.addEventListener( MouseEvent.MOUSE_UP, OnButtonClick );
			}
			addChild(mButtonHolder);
			mButtonHolder.x = 0;
			mButtonHolder.y = stage.stageHeight - (kPanelHPercent * stage.stageHeight / 100) + mButtonHolder.height/2;
			
			// Add the inventory
			if(mInventoryPosition == null)
			{
				mScummInventory.x = (this.stage.stageWidth / 2) - 14;
				mScummInventory.y = mBackPanel.y + mFeedbackText.height + 1 ;
			}
			else
			{
				mScummInventory.x = mInventoryPosition.x ;
				mScummInventory.y = mInventoryPosition.y ;
				mInventoryPosition = null ;
			}
			
			
			addChild(mScummInventory);
			SetInventoryDisplayListeners( mScummInventory );
			
			stage.addEventListener(MouseEvent.MOUSE_MOVE, OnMouseMove );
			
			addEventListener(Event.REMOVED_FROM_STAGE, OnRemovedToStage );
			
			stage.addEventListener(Event.RESIZE, resizeStage);
			
			mScummInventory.y = stage.stageHeight - (23 * stage.stageHeight / 100);
			mScummInventory.x = (this.stage.stageWidth / 2) - 14;
			mScummInventory.height = (23 * stage.stageHeight / 100);
			mScummInventory.width = (50.5 * stage.stageHeight / 100);
			
			mButtonHolder.x = 0;
			mButtonHolder.y = stage.stageHeight - (kPanelHPercent * stage.stageHeight / 100) + mScummInventory.height/4;
			
			mBackPanel.width = stage.stageWidth;
			mBackPanel.height = (kPanelHPercent * stage.stageHeight / 100);
			mBackPanel.y = stage.stageHeight - (kPanelHPercent * stage.stageHeight / 100);
			//mInfoBox.y = root.stage.stageHeight-(mInfoBox.height+mInventory.height);
			//mInfoBox.x = 0;
			//mInfoBox.width = stage.stageWidth;
			
		}
		
		private function resizeStage(e:Event):void
		{	
			mScummInventory.y = stage.stageHeight - (23 * stage.stageHeight / 100);
			mScummInventory.x = (this.stage.stageWidth / 2) - 14;
			mScummInventory.height = (23 * stage.stageHeight / 100);
			mScummInventory.width = (50.5 * stage.stageHeight / 100);
			
			mButtonHolder.x = 0;
			mButtonHolder.y = stage.stageHeight - (kPanelHPercent * stage.stageHeight / 100) + mScummInventory.height/4;
			
			mBackPanel.width = stage.stageWidth;
			mBackPanel.height = (kPanelHPercent * stage.stageHeight / 100);
			mBackPanel.y = stage.stageHeight - (kPanelHPercent * stage.stageHeight / 100);
			mFeedbackText.x = stage.stageWidth/2 - mFeedbackText.width/2;
			mFeedbackText.y = mBackPanel.y ;
		}
		
		protected function OnRemovedToStage(event:Event):void
		{
			removeEventListener(Event.REMOVED_FROM_STAGE, OnRemovedToStage );
			
			stage.removeEventListener(MouseEvent.MOUSE_MOVE, OnMouseMove );
			
			// remove listeners from buttons.
			for each( var button:WakSimpleButton in mButtonsArray)
			{
				button.removeEventListener( MouseEvent.CLICK, OnButtonClick );
			}
			//mScummInventory.RemoveGuiListeners( this );
			RemoveInventoryDisplayListeners( mScummInventory );
			
			addEventListener(Event.ADDED_TO_STAGE, OnAddedToStage );
		}
		
		protected function SetInventoryDisplayListeners( pInvDisplay:ScummInventoryDisplay ):void
		{
			pInvDisplay.addEventListener(GuiEvent.INVENTORY_ITEM_OUT, OnInventoryItemOut );
			pInvDisplay.addEventListener(GuiEvent.INVENTORY_ITEM_OVER, OnInventoryItemOver );
			pInvDisplay.addEventListener(GuiEvent.INVENTORY_ITEM_SELECTED, OnInventoryItemClick );
		}
		
		protected function RemoveInventoryDisplayListeners( pInvDisplay:ScummInventoryDisplay ):void
		{
			pInvDisplay.removeEventListener(GuiEvent.INVENTORY_ITEM_OUT, OnInventoryItemOut );
			pInvDisplay.removeEventListener(GuiEvent.INVENTORY_ITEM_OVER, OnInventoryItemOver );
			pInvDisplay.removeEventListener(GuiEvent.INVENTORY_ITEM_SELECTED, OnInventoryItemClick );
		}
		
		protected function OnMouseMove(event:MouseEvent):void
		{
				
			mMouseCursor.x = event.stageX ;
			mMouseCursor.y = event.stageY ;
			
			if(!mEnabled)
				return ;
				
			// update the buttons
			for each( var button:WakSimpleButton in mButtonsArray)
			{
				button.Update( event.stageX, event.stageY );
			}
			
		}
		

		
		/**
		 * Load the settings of the gui using the parameters in pSettings 
		 * @param pSettings XML with the settings.
		 * 
		 */		
		protected function LoadSettings( pSettings:XML ):void
		{
			//trace("LoadSettings:"+pSettings.PanelColor);
			mPanelColor = uint( "0x"+pSettings.PanelColor ) ;
			
			if(pSettings.PanelBg != "")
				mPanelBg = new mResourceManager[pSettings.PanelBg] as DisplayObject ;
				
			if(pSettings.FeedbackFont != "")
				mFeedbackFont = pSettings.FeedbackFont ;
				
			if(pSettings.FeedbackColor != "")
				mFeedbackFontColor = uint( "0x"+pSettings.FeedbackColor ) ;
			
			if(pSettings.FeedbackHighlightColor != "")
				mFeedbackFontHLColor = uint( "0x"+pSettings.FeedbackHighlightColor ) ;
				
			if(pSettings.FeedbackFontSize != "")
				mFeedbackSize = int( pSettings.FeedbackFontSize ) ;
				
				
			for each( var button:XML in pSettings.Button)
			{
				if( (button.Up != "") && (button.Over != "") && (button.Down != "") )
				{
					CreateButton(button);
				}
				else
				{
					CreateDefaultButton( button.@action );
				}
			}
			
			// Load settings for the inventory.
			
			var fInvPos:XMLList = pSettings.Inventory.Position ;
			if( (fInvPos.@x != "") && (fInvPos.@y != "") )
			{
				mInventoryPosition = new Point(fInvPos.@x,fInvPos.@y);
			}
			
			mInventoryRows = pSettings.Inventory.Rows ;
			mInventoryCols = pSettings.Inventory.Cols ;
			
			mInventoryItemWidth = pSettings.Inventory.ItemWidth ;
			mInventoryItemHeight = pSettings.Inventory.ItemHeight ;
			
			// Load the scrolling buttons
			var fNewBtn:WakSimpleButton = null ;
			var fOver:DisplayObject = null ;
			var fUp:DisplayObject = null ;
			var fDown:DisplayObject = null ;
			
			for each( var btn:XML in pSettings.Inventory.Button)
			{
				if((btn.Up != "") && (btn.Over != "") && (btn.Down != "") )
				{
					fUp = new mResourceManager[btn.Up] as DisplayObject;
					fOver = new mResourceManager[btn.Over] as DisplayObject;
					fDown = new mResourceManager[btn.Down] as DisplayObject;
					fNewBtn= new WakSimpleButton(fUp,fOver,fDown);
					if(btn.@id == "ScrollUp")
					{
						mInvScrollBtnUp = fNewBtn ;
					}
					else if(btn.@id == "ScrollDown")
					{
						mInvScrollBtnDown = fNewBtn ;
					}
				}
			}
			
		}
		
		private const kCol1Width:Number = 76 ;
		private const kCol2Width:Number = 124 ;
		
		private var kRow1Y:Number = 0;
		private const kRow2Y:Number = 28 ;
		private const kRow3Y:Number = 55;
		
		private const kCol1X:Number = 2 ;
		private const kCol2X:Number = 82 ;
		private const kCol3X:Number = 210 ;
		private const kBtnH:Number = 26 ;
		
		protected function CreateButton(pButtonXml:XML):void
		{
			var fButton:WakSimpleButton = null ;
			var fBtnX:Number = 0 ;
			var fBtnY:Number = 0 ;
			
			var fUp:DisplayObject = new mResourceManager[pButtonXml.Up]  ;
			var fOver:DisplayObject = new mResourceManager[pButtonXml.Over]  ;
			var fDown:DisplayObject = new mResourceManager[pButtonXml.Down]  ;
			
			var fButtonId:String = pButtonXml.@action ;
			
			if(fButtonId == "")
			{
				return ;
			}
			
			switch( fButtonId )
			{
				case AdventureActions.ActionIdGive:
				fBtnX = kCol1X ;
				fBtnY = kRow1Y ;
				break ;
				case AdventureActions.ActionIdOpen:
				fBtnX = kCol1X ;
				fBtnY = kRow2Y ;
				break ;
				case AdventureActions.ActionIdClose:
				fBtnX = kCol1X ;
				fBtnY = kRow3Y ;
				break ;
				
				case AdventureActions.ActionIdPickUp:
				fBtnY = kRow1Y ;
				fBtnX = kCol2X ;
				break ;
				case AdventureActions.ActionIdLookAt:
				fBtnY = kRow2Y ;
				fBtnX = kCol2X ;
				break ;
				case AdventureActions.ActionIdTalkTo:
				fBtnY = kRow3Y ;
				fBtnX = kCol2X ;
				break ;
				
				case AdventureActions.ActionIdUse:
				fBtnY = kRow1Y ;
				fBtnX = kCol3X ;
				break ;
				case AdventureActions.ActionIdPush:
				fBtnY = kRow2Y ;
				fBtnX = kCol3X ;
				break ;
				case AdventureActions.ActionIdPull :
				fBtnY = kRow3Y ;
				fBtnX = kCol3X ;
				break ;
			}
			
			fButton = new WakSimpleButton(fUp,fOver,fDown, fButtonId);
			fButton.x = fBtnX ;
			fButton.y = fBtnY - stageHeight;
			mButtonsArray.push(fButton);
			mButtonsByNameArray[fButtonId] = fButton ;
		}
		
		public function stageSize():void
		{
			stageHeight = root.stage.stageHeight;
		}
		protected function CreateDefaultButton( pButtonId:String ):void
		{
			var fButton:WakSimpleButton = null ;
			var fBtnX:Number = 0 ;
			var fBtnY:Number = 0 ;
			var fBtnW:Number = 0 ;
			//stageSize();
			//trace("height",stageHeight);
			var fOver:Sprite = new Sprite();
			var fUp:Sprite = new Sprite();
			var fDown:Sprite = new Sprite();
			
			
			
			switch( pButtonId )
			{
				case AdventureActions.ActionIdGive:
				fBtnW = kCol1Width ;
				fBtnX = kCol1X ;
				fBtnY = kRow1Y ;
				break ;
				case AdventureActions.ActionIdOpen:
				fBtnW = kCol1Width ;
				fBtnX = kCol1X ;
				fBtnY = kRow2Y ;
				break ;
				case AdventureActions.ActionIdClose:
				fBtnW = kCol1Width ;
				fBtnX = kCol1X ;
				fBtnY = kRow3Y ;
				break ;
				
				case AdventureActions.ActionIdPickUp:
				fBtnW = kCol2Width ;
				fBtnY = kRow1Y;
				fBtnX = kCol2X ;
				break ;
				case AdventureActions.ActionIdLookAt:
				fBtnW = kCol2Width ;
				fBtnY = kRow2Y ;
				fBtnX = kCol2X ;
				break ;
				case AdventureActions.ActionIdTalkTo:
				fBtnW = kCol2Width ;
				fBtnY = kRow3Y;
				fBtnX = kCol2X ;
				break ;
				
				case AdventureActions.ActionIdUse:
				fBtnW = kCol1Width ;
				fBtnY = kRow1Y;
				fBtnX = kCol3X ;
				break ;
				case AdventureActions.ActionIdPush:
				fBtnW = kCol1Width ;
				fBtnY = kRow2Y;
				fBtnX = kCol3X ;
				break ;
				case AdventureActions.ActionIdPull:
				fBtnW = kCol1Width ;
				fBtnY = kRow3Y;
				fBtnX = kCol3X ;
				break ;
			}
			
			var fUpTxt:TextField = new TextField();			
			var fOverTxt:TextField = new TextField();
			var fDownTxt:TextField = new TextField();
			
			fUpTxt.embedFonts = true ;
			fUpTxt.defaultTextFormat = mButtonStyle ;
			fUpTxt.text = GetButtonLabel( pButtonId );
			fUpTxt.selectable = false ;
			fUpTxt.width = fBtnW ;
			fUpTxt.height = kBtnH ;
			fUpTxt.mouseEnabled = false ;
			//fUpTxt.borderColor = 0xFFFFFF ;
			//fUpTxt.border = true ;
			
			fOverTxt.embedFonts = fUpTxt.embedFonts ;
			fOverTxt.defaultTextFormat = mButtonOverStyle ;
			fOverTxt.text = fUpTxt.text ;
			fOverTxt.selectable = false ;
			fOverTxt.width = fBtnW ;
			fOverTxt.height = kBtnH ;
			fOverTxt.mouseEnabled = false ; 
			
			fDownTxt.embedFonts = fUpTxt.embedFonts ;
			fDownTxt.defaultTextFormat = mButtonOverStyle ;
			fDownTxt.text = fUpTxt.text ;
			fDownTxt.selectable = false ;
			fDownTxt.width = fBtnW ;
			fDownTxt.height = kBtnH ;
			fDownTxt.mouseEnabled = false ;
			
			
			
			/////
			fUp.graphics.beginFill( 0x120012 );
			//fUp.graphics.beginFill( 0xFFFFFF );
			fUp.graphics.drawRect(0, 0, fBtnW, kBtnH);
			fUp.graphics.endFill() ;
			fUp.addChild(fUpTxt);
			
			fOver.graphics.beginFill( 0x120012 );
			fOver.graphics.drawRect(0, 0, fBtnW, kBtnH);
			fOver.graphics.endFill() ;
			fOver.addChild(fOverTxt);
			
			fDown.graphics.beginFill( 0x312331 );
			fDown.graphics.drawRect(0, 0, fBtnW, kBtnH);
			fDown.graphics.endFill() ;
			fDown.addChild(fDownTxt);
			
			fButton = new WakSimpleButton(fUp, fOver, fDown, pButtonId);
			fButton.x = fBtnX ;
			fButton.y = fBtnY;
			trace(fBtnY);
			fButton.useHandCursor = false ;
			
			mButtonsArray.push(fButton);
			mButtonsByNameArray[pButtonId] = fButton ;
						
		}
		
		private function GetButtonLabel( pId:String ):String
		{
			var pLabel:String = "" ;
			
			switch(pId)
			{
				case AdventureActions.ActionIdGive :
					pLabel = mTextManager.GiveText ;
				break ;
				case AdventureActions.ActionIdOpen :
					pLabel = mTextManager.OpenText ;
				break ;
				case AdventureActions.ActionIdClose :
					pLabel = mTextManager.CloseText ;
				break ;
				
				case AdventureActions.ActionIdPickUp :
					pLabel = mTextManager.PickupText ;
				break ;
				case AdventureActions.ActionIdLookAt:
					pLabel = mTextManager.LookatText ;
				break ;
				case AdventureActions.ActionIdTalkTo :
					pLabel = mTextManager.TalktoText ;
				break ;
				
				case AdventureActions.ActionIdUse:
					pLabel = mTextManager.UseText ;
				break ;
				case AdventureActions.ActionIdPush :
					pLabel = mTextManager.PushText ;
				break ;
				case AdventureActions.ActionIdPull :
					pLabel = mTextManager.PullText ;
				break ;
				
			}
			
			return pLabel ;
		}
		
		public function get display():DisplayObject
		{
			return this;
		}
		
		private function OnButtonClick(event:Event):void
		{
			if(!mEnabled)
				return ;
			
			var fTarget:DisplayObject = event.target as DisplayObject ;
			
			var fButton:WakSimpleButton = null ;
			
			fButton = event.currentTarget as WakSimpleButton ;
			
			
			if(fButton == null)
				return ;
			
			var fEvent:GuiEvent = new GuiEvent( GuiEvent.ACTION_SELECTED, fButton.buttonName );
			this.dispatchEvent( fEvent );
		}
		
		private function OnInventoryItemOver(event:GuiEvent):void
		{
			if(!mEnabled)
				return ;
				
			var fEvent:GuiEvent = new GuiEvent(event.type,"",event.inventoryItem);
			this.dispatchEvent( fEvent );
		}
		
		private function OnInventoryItemOut(event:GuiEvent):void
		{
			if(!mEnabled)
				return ;
				
			var fEvent:GuiEvent = new GuiEvent(event.type,"",event.inventoryItem);
			this.dispatchEvent( fEvent );
		}
		
		private function OnInventoryItemClick(event:GuiEvent):void
		{
			if(!mEnabled)
				return ;
				
			var fEvent:GuiEvent = new GuiEvent(event.type,"",event.inventoryItem);
			this.dispatchEvent( fEvent );
			
			/* 
			var fItem:InventoryItem = AdventureMaster.InventoryItemsMngr.GetInventoryItem("IShovel");
			var fChar:AdventureCharacter = AdventureMaster.CharactersMngr.GetCharacter( AdventureMaster.defaultPlayerCharacterId ) 
			fChar.inventory.AddItem( fItem );
			 */
		}
		
		
		public function set enabled(value:Boolean):void
		{
			mEnabled = value ;
			this.visible = value ;
		}
		
		public function get enabled():Boolean 
		{
			return mEnabled ;
		}
		
		
		
		
	}
}